from rest_framework.viewsets import ModelViewSet

from utils.pagination import TenItemPerPagePagination
from warehouse.models import Warehouse
from warehouse.serializers import WarehouseModelSerializer


class WarehouseViewSet(ModelViewSet):
    queryset = Warehouse.objects.filter(is_delete=False).order_by("-c_time")
    serializer_class = WarehouseModelSerializer
    pagination_class = TenItemPerPagePagination
    ordering_fields = ['c_time']

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()  # 逻辑删除
